//package com.xiaode.util;
//
//import com.jfinal.kit.PathKit;
//import com.jfinal.plugin.activerecord.Db;
//import com.jfinal.plugin.activerecord.Record;
//import com.xiaode.common.model.Example;
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.nio.channels.FileChannel;
//import java.util.List;
//
//public class dealPic {
//    public void delPic() throws IOException {
//        FileChannel inputChannel = null;
//        FileChannel outputChannel = null;
//        try {
//            List<Record> records = Db.find("SELECT a.pictureUrl,a.num FROM(SELECT pictureUrl,COUNT(*) num FROM `example` GROUP BY pictureUrl) a WHERE a.num > 1");
//            String webRootPath = PathKit.getWebRootPath();
//            System.out.println(webRootPath);
//            for (int i = 0; i < records.size(); i++) {
//                Record record = records.get(i);
//                String pictureUrl = record.getStr("pictureUrl");
//                Integer num = record.getInt("num");
//                File file = new File(webRootPath + "/" + pictureUrl);
//                List<Example> examples = Example.dao.find("SELECT * FROM `example` where pictureUrl = ?", pictureUrl);
//                if (file.exists()) {
//                    inputChannel = new FileInputStream(file).getChannel();
//                    for (Integer j = 0; j < num; j++) {
//                        File file1 = new File(file.getAbsolutePath() +"_"+"j");
//                        outputChannel = new FileOutputStream(file1).getChannel();
//                        outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
//                        Example example = examples.get(j);
//                        example.setPictureUrl(example.getPictureUrl()+"_"+j);
//                    }
//                }
//                Db.batchUpdate(examples,num);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            if (inputChannel!= null) {
//                inputChannel.close();
//            }
//            if (outputChannel!=null) {
//                outputChannel.close();
//            }
//        }
//    }
//}
